/*
 * CManager.h
 *
 *  Created on: 2016-4-14
 *      Author: root
 */

#ifndef CMUTILTHREADMANAGER_H_
#define CMUTILTHREADMANAGER_H_
#include"PublicTool.h"
#if USE_THREAD_MANAGER
#include"PublicThread.h"
//基类
typedef enum _ThreadStatus{
THREAD_NULL=0,//线程未启动
THREAD_RUNNING,//线程工作中
THREAD_STOPPED//线程已停止
}ThreadStatus;
typedef struct _ThreadInfo{
pthread_t    threadid;
ThreadStatus status;
}ThreadInfo;
class CMultiThreadManager{
//线程锁
    PublicLock m_Thread_Mutex;
    ThreadInfo*m_ThreadInfoList;
//线程数量
    void*m_usrdata;//用户数据
    thrfunc* m_func;//需执行的线程
protected:
    int m_ThreadNum;
public:
    char m_ThreadMode[128];
    int  m_ThreadRunning;
public:
    CMultiThreadManager();
    virtual ~CMultiThreadManager();
    void StartWorkThread(thrfunc*funfunc,void*usrdata,int ThreadNum,const char*threadname);
    void StopWorkThread();
    static  void*WorkThread(void*argv);
    void RunWorkThreadMain();
//更新线程状态
    void UpdateThreadStatus(pthread_t threadid,ThreadStatus status);
//线程相关
private:
//线程是否开启停止标志    
    bool IsThreadRunningFlag();
//是否所有线程运行着
    bool IsAllThreadsRunning();
//是否所有线程运行着
    bool IsAllThreadsStopped();
};
#endif
#endif /* CMANAGER_H_ */
